<?php

/**
 * @Project NUKEVIET 3.x - GETNEWS
 * @Author ĐẶNG ĐÌNH TỨ (dlinhvan@gmail.com)
 * @Copyright (C) 2010 webdep24.com All rights reserved
 * @Createdate 10/08/2012 08:00
 */

if( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
$page_title = $lang_module['config'];
$contents = "";
$error = "";
$data = array();
$zing = $nv_Request->get_int( 'zing', 'post', 0 );
$vnex = $nv_Request->get_int( 'vnex', 'post', 0 );
$ngoisao = $nv_Request->get_int( 'ngoisao', 'post', 0 );
$dt = $nv_Request->get_int( 'dt', 'post', 0 );
$h24h = $nv_Request->get_int( '24h', 'post', 0 );

$save1 = $nv_Request->isset_request( 'confirm1', 'post' );
$save2 = $nv_Request->isset_request( 'confirm2', 'post' );
$save3 = $nv_Request->isset_request( 'confirm3', 'post' );
$save4 = $nv_Request->isset_request( 'confirm4', 'post' );
$save5 = $nv_Request->isset_request( 'confirm5', 'post' );

$cat = filter_text_input( 'cat', 'post', '' );
if( $zing == 1 or $vnex == 1 or $ngoisao == 1 or $dt == 1 or $h24h == 1 )
{
	if( $save1 or $save2 or $save3 or $save4 or $save5 )
	{
		$data['title'] = filter_text_input( 'title', 'post', '' );
		$data['link'] = filter_text_input( 'link', 'post', '' );

		if( $data['title'] == "" )
		{
			$error .= "Bạn chưa nhập chuyên mục";
		}
		elseif( $data['link'] == "" )
		{
			$error = "Bạn chưa nhập link";
		}
		else
		{
			if( $zing == 1 ) $hauto = "zing";
			if( $vnex == 1 ) $hauto = "vnex";
			if( $ngoisao == 1 ) $hauto = "ngoisao";
			if( $dt == 1 ) $hauto = "dt";
			if( $h24h == 1 ) $hauto = "h24h";

			$query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_" . $hauto . "` VALUES( NULL," . $db->dbescape( $data['title'] ) . "," . $db->dbescape( $data['link'] ) . ")";
			if( $db->sql_query_insert_id( $query ) )
			{
				$db->sql_freeresult();
				Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
				die();
			}
			else
			{
				$error .= "Không thể lưu dữ liệu được";
			}
		}
	}
}
if( $error )
{
	$contents .= "   
<div class=\"quote\" style=\"width: 780px;\">        
	<blockquote class=\"error\"><span style=\"font-size:16px\">" . $error . "</span>        
	</blockquote></div><div class=\"clear\">
</div>";
}

// zing1
$contents .= "<form method=\"post\">";
$contents .= "	<table class=\"tab1\">";
$contents .= "		<thead>";
$contents .= "			<tr>";
$contents .= "				<td colspan=\"7\">" . $lang_module['info_zing'] . "";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</thead>";
$contents .= "		<tbody>";
$contents .= "			<tr>  ";
$contents .= "				<td></td>";
$contents .= "				<td style=\"width:210px;\"><input style=\"width:200px;\" name=\"title\" value=\"\" type=\"text\"></td>";
$contents .= "				<td style=\"width:310px;\"><input style=\"width:300px;\" name=\"link\" value=\"\" type=\"text\"></td>";
$contents .= "				<td style=\"width:40px;\" align=\"center\">";
$contents .= "					<input type=\"hidden\" name=\"zing\" id=\"zing\" value=\"1\">";
$contents .= "					<input style=\"width:60px;\" name=\"confirm1\" value=\"Lưu\" type=\"submit\">";
$contents .= "				</td>";
$contents .= "				<td>";
$contents .= "					<form method=\"post\">";
$contents .= "						<select name=\"cat\" style=\"width:160px;\">";
$sql = "SELECT id, title, link FROM `" . NV_PREFIXLANG . "_" . $module_data . "_zing`";
$result = $db->sql_query( $sql );
while( $row = $db->sql_fetchrow( $result ) )
{
	$select = ( $cat == $row['id'] ) ? " selected=\"selected\"" : "";
	$contents .= "						<option " . $select . " value=\"" . $row['id'] . "\">" . $row['title'] . "</option>";
}
if( $nv_Request->isset_request( 'del_zing', 'post' ) )
{
	$sql1 = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_zing` WHERE `id`=" . $cat;
	$result = $db->sql_query( $sql1 );
}
$contents .= "						</select>";
$contents .= "						<input style=\"width:60px;\" name=\"del_zing\" value=\"Xóa\" type=\"submit\">";
$contents .= "					</form>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</tbody>";
$contents .= "	</table>";
$contents .= "</form>";

// vnexpress.net2
$contents .= "<form method=\"post\">";
$contents .= "	<table class=\"tab1\">";
$contents .= "		<thead>";
$contents .= "			<tr>";
$contents .= "				<td colspan=\"7\">" . $lang_module['info_vnex'] . "";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</thead>";
$contents .= "		<tbody>";
$contents .= "			<tr>  ";
$contents .= "				<td></td>";
$contents .= "				<td style=\"width:210px;\"><input style=\"width:200px;\" name=\"title\" value=\"\" type=\"text\"></td>";
$contents .= "				<td style=\"width:310px;\"><input style=\"width:300px;\" name=\"link\" value=\"\" type=\"text\"></td>";
$contents .= "				<td  style=\"width:40px;\" align=\"center\">";
$contents .= "					<input type=\"hidden\" name=\"vnex\" id=\"vnex\" value=\"1\">";
$contents .= "					<input style=\"width:60px;\" name=\"confirm2\" value=\"Lưu\" type=\"submit\">";
$contents .= "				</td>";
$contents .= "				<td>";
$contents .= "					<form method=\"post\">";
$contents .= "						<select name=\"cat\" style=\"width:160px;\">";
$sql = "SELECT id, title, link FROM `" . NV_PREFIXLANG . "_" . $module_data . "_vnex`";
$result = $db->sql_query( $sql );
while( $row = $db->sql_fetchrow( $result ) )
{
	$select = ( $cat == $row['id'] ) ? " selected=\"selected\"" : "";
	$contents .= "						<option " . $select . " value=\"" . $row['id'] . "\">" . $row['title'] . "</option>";
}
if( $nv_Request->isset_request( 'del_vnex', 'post' ) )
{
	$sql1 = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_vnex` WHERE `id`=" . $cat;
	$result = $db->sql_query( $sql1 );
}
$contents .= "						</select>";
$contents .= "						<input style=\"width:60px;\" name=\"del_vnex\" value=\"Xóa\" type=\"submit\">";
$contents .= "					</form>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</tbody>";
$contents .= "	</table>";
$contents .= "</form>";

// ngoisao3
$contents .= "<form method=\"post\">";
$contents .= "	<table class=\"tab1\">";
$contents .= "		<thead>";
$contents .= "			<tr>";
$contents .= "				<td colspan=\"7\">" . $lang_module['info_ngoisao'] . "<strong style=\"color:#fff\"> Chú ý website này sử dụng nguồn Rss Click <a style=\"color:red\" href='javascript:void(0);' onclick=\"window.open('http://ngoisao.net/rss/#CContainer','popup','width=800,height=600,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=0'); return false\">Link Rss</a><strong>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</thead>";
$contents .= "		<tbody>";
$contents .= "			<tr>  ";
$contents .= "				<td></td>";
$contents .= "				<td style=\"width:210px;\"><input style=\"width:200px;\" name=\"title\" value=\"\" type=\"text\"></td>";
$contents .= "				<td style=\"width:310px;\"><input style=\"width:300px;\" name=\"link\" value=\"\" type=\"text\"></td>";
$contents .= "				<td  style=\"width:40px;\" align=\"center\">";
$contents .= "					<input type=\"hidden\" name=\"ngoisao\" id=\"ngoisao\" value=\"1\">";
$contents .= "					<input style=\"width:60px;\" name=\"confirm3\" value=\"Lưu\" type=\"submit\">";
$contents .= "				</td>";
$contents .= "				<td>";
$contents .= "					<form method=\"post\">";
$contents .= "						<select name=\"cat\" style=\"width:160px;\">";
$sql = "SELECT id, title, link FROM `" . NV_PREFIXLANG . "_" . $module_data . "_ngoisao`";
$result = $db->sql_query( $sql );
while( $row = $db->sql_fetchrow( $result ) )
{
	$select = ( $cat == $row['id'] ) ? " selected=\"selected\"" : "";
	$contents .= "						<option " . $select . " value=\"" . $row['id'] . "\">" . $row['title'] . "</option>";
}
if( $nv_Request->isset_request( 'del_ngoisao', 'post' ) )
{
	$sql1 = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_ngoisao` WHERE `id`=" . $cat;
	$result = $db->sql_query( $sql1 );
}
$contents .= "						</select>";
$contents .= "						<input style=\"width:60px;\" name=\"del_ngoisao\" value=\"Xóa\" type=\"submit\">";
$contents .= "					</form>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</tbody>";
$contents .= "	</table>";
$contents .= "</form>";

// 24h4
$contents .= "<form method=\"post\">";
$contents .= "	<table class=\"tab1\">";
$contents .= "		<thead>";
$contents .= "			<tr>";
$contents .= "				<td colspan=\"7\">" . $lang_module['info_h24h'] . "";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</thead>";
$contents .= "		<tbody>";
$contents .= "			<tr>  ";
$contents .= "				<td></td>";
$contents .= "				<td style=\"width:210px;\"><input style=\"width:200px;\" name=\"title\" value=\"\" type=\"text\"></td>";
$contents .= "				<td style=\"width:310px;\"><input style=\"width:300px;\" name=\"link\" value=\"\" type=\"text\"></td>";
$contents .= "				<td  style=\"width:40px;\" align=\"center\">";
$contents .= "					<input type=\"hidden\" name=\"h24h\" id=\"h24h\" value=\"1\">";
$contents .= "					<input style=\"width:60px;\" name=\"confirm4\" value=\"Lưu\" type=\"submit\">";
$contents .= "				</td>";
$contents .= "				<td>";
$contents .= "					<form method=\"post\">";
$contents .= "						<select name=\"cat\" style=\"width:160px;\">";
$sql = "SELECT id, title, link FROM `" . NV_PREFIXLANG . "_" . $module_data . "_24h`";
$result = $db->sql_query( $sql );
while( $row = $db->sql_fetchrow( $result ) )
{
	$select = ( $cat == $row['id'] ) ? " selected=\"selected\"" : "";
	$contents .= "						<option " . $select . " value=\"" . $row['id'] . "\">" . $row['title'] . "</option>";
}
if( $nv_Request->isset_request( 'del_h24h', 'post' ) )
{
	$sql1 = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_24h` WHERE `id`=" . $cat;
	$result = $db->sql_query( $sql1 );
}
$contents .= "						</select>";
$contents .= "						<input style=\"width:60px;\" name=\"del_h24h\" value=\"Xóa\" type=\"submit\">";
$contents .= "					</form>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</tbody>";
$contents .= "	</table>";
$contents .= "</form>";

// dantri5
$contents .= "<form method=\"post\">";
$contents .= "	<table class=\"tab1\">";
$contents .= "		<thead>";
$contents .= "			<tr>";
$contents .= "				<td colspan=\"7\">" . $lang_module['info_dt'] . "<strong style=\"color:#fff\"> Chú ý website này sử dụng nguồn 2 nguồn chuyên mục trên trang chính và Rss Click <a style=\"color:red\" href='javascript:void(0);' onclick=\"window.open('http://dantri.com.vn/rss/#rss','popup','width=800,height=600,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=0'); return false\">Link Rss</a><strong>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</thead>";
$contents .= "		<tbody>";
$contents .= "			<tr>  ";
$contents .= "				<td></td>";
$contents .= "				<td style=\"width:210px;\"><input style=\"width:200px;\" name=\"title\" value=\"\" type=\"text\"></td>";
$contents .= "				<td style=\"width:310px;\"><input style=\"width:300px;\" name=\"link\" value=\"\" type=\"text\"></td>";
$contents .= "				<td  style=\"width:40px;\" align=\"center\">";
$contents .= "					<input type=\"hidden\" name=\"dt\" id=\"dt\" value=\"1\">";
$contents .= "					<input style=\"width:60px;\" name=\"confirm5\" value=\"Lưu\" type=\"submit\">";
$contents .= "				</td>";
$contents .= "				<td>";
$contents .= "					<form method=\"post\">";
$contents .= "						<select name=\"cat\" style=\"width:160px;\">";
$sql = "SELECT id, title, link FROM `" . NV_PREFIXLANG . "_" . $module_data . "_dt`";
$result = $db->sql_query( $sql );
while( $row = $db->sql_fetchrow( $result ) )
{
	$select = ( $cat == $row['id'] ) ? " selected=\"selected\"" : "";
	$contents .= "						<option " . $select . " value=\"" . $row['id'] . "\">" . $row['title'] . "</option>";
}
if( $nv_Request->isset_request( 'del_dt', 'post' ) )
{
	$sql1 = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_dt` WHERE `id`=" . $cat;
	$result = $db->sql_query( $sql1 );
}
$contents .= "						</select>";
$contents .= "						<input style=\"width:60px;\" name=\"del_dt\" value=\"Xóa\" type=\"submit\">";
$contents .= "					</form>";
$contents .= "				</td>";
$contents .= "			</tr>";
$contents .= "		</tbody>";
$contents .= "	</table>";
$contents .= "</form>";

include ( NV_ROOTDIR . "/includes/header.php" );
echo nv_admin_theme( $contents );
include ( NV_ROOTDIR . "/includes/footer.php" );

?>